home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Informant Complete 1995 - 2000
/
Delphi Informant Complete 1995 to 2000.iso
/
Delphi Informant Magazine Complete Works SOURCE CODE 1995.rar
/
1995
/
SEP
/
RH9509
/
EXAMPLE2
/
MAIN.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-08-15
|
6KB
|
167 lines
unit Main; { Example 2 -- How to use class TProfilingStopWatch. }
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, StpWatch, VTimerDv;
type
TMainFrm = class(TForm)
{ Non-Visual components }
ProfilingStopWatch1: TProfilingStopWatch;
ProfilingStopWatch2: TProfilingStopWatch;
ProfilingStopWatch3: TProfilingStopWatch;
ProfilingStopWatch4: TProfilingStopWatch;
{ Visual components }
RunBtn: TButton;
RecalibrateBtn: TButton;
SetOverheadBtn: TButton;
IterationsEbx: TEdit;
StopOverheadEbx: TEdit;
SplitOverheadEbx: TEdit;
TotalTimeLbl: TLabel;
TotalPctLbl: TLabel;
EmptyTimeLbl: TLabel;
EmptyPctLbl: TLabel;
SplitTimeLbl: TLabel;
SplitPctLbl: TLabel;
WorkTimeLbl: TLabel;
WorkPctLbl: TLabel;
OverheadLbl: TLabel;
OverheadPctLbl: TLabel;
RemainderLbl: TLabel;
RemainderPctLbl: TLabel;
StopOverheadLbl: TLabel;
SplitOverheadLbl: TLabel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
{ Methods }
procedure FormActivate(Sender: TObject);
procedure RunBtn_Click(Sender: TObject);
procedure RecalibrateBtn_Click(Sender: TObject);
procedure SetOverheadBtn_Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainFrm: TMainFrm;
implementation
{$R *.DFM}
procedure TMainFrm.FormActivate(Sender: TObject);
begin
IterationsEbx.Text := '10';
StopOverheadEbx.Text := FormatFloat('0.0000000',TProfilingStopWatch.GetOverheadForStop);
SplitOverheadEbx.Text := FormatFloat('0.0000000',TProfilingStopWatch.GetOverheadForSplit);
RunBtn.SetFocus;
RunBtn_Click(self);
end;
procedure TMainFrm.RunBtn_Click(Sender: TObject);
var
i,j,NumIterations,NumInnerStops,NumInnerSplits: longint;
x,TotalTime,EmptyTime,WorkTime,Overhead,Remainder,SplitTime: double;
begin
NumIterations := StrToInt(IterationsEbx.Text);
ProfilingStopWatch1.Reset;
ProfilingStopWatch2.Reset;
ProfilingStopWatch3.Reset;
ProfilingStopWatch4.Reset;
NumInnerStops := 0;
NumInnerSplits := 0;
{ Start the overall timer. }
ProfilingStopWatch1.Start;
{ The "empty" loop }
for i := 1 to NumIterations do
begin
ProfilingStopWatch2.Start;
ProfilingStopWatch2.Stop;
NumInnerStops := NumInnerStops + 2;
end;
{ The "split" loop }
ProfilingStopWatch3.Start;
for i := 1 to NumIterations do
SplitTime := ProfilingStopWatch3.ElapsedTime; { Get split time }
ProfilingStopWatch3.Stop;
inc(NumInnerStops);
NumInnerSplits := NumInnerSplits + NumIterations;
{ The "work" loop }
ProfilingStopWatch4.Start;
inc(NumInnerStops);
x := 1.0;
for i := 1 to NumIterations do
for j := 1 to i do
begin
x := sqrt(x);
x := ln(x);
x := exp(x);
x := x * x;
end;
ProfilingStopWatch4.Stop;
inc(NumInnerStops);
{ Stop the overall timer. }
ProfilingStopWatch1.Stop;
{ Format and display the results. }
TotalTime := ProfilingStopWatch1.ElapsedTime;
EmptyTime := ProfilingStopWatch2.ElapsedTime;
SplitTime := ProfilingStopWatch3.ElapsedTime;
WorkTime := ProfilingStopWatch4.ElapsedTime;
Overhead := NumInnerStops*TProfilingStopWatch.GetOverheadForStop
+ NumInnerSplits*TProfilingStopWatch.GetOverheadForSplit;
Remainder := TotalTime - EmptyTime - SplitTime - WorkTime - Overhead;
TotalTimeLbl.Caption := FormatFloat('0.000000',TotalTime);
EmptyTimeLbl.Caption := FormatFloat('0.000000',EmptyTime);
SplitTimeLbl.Caption := FormatFloat('0.000000',SplitTime);
WorkTimeLbl.Caption := FormatFloat('0.000000',WorkTime);
OverheadLbl.Caption := FormatFloat('0.000000',Overhead);
RemainderLbl.Caption := FormatFloat('0.000000',Remainder);
TotalPctLbl.Caption := '100.00';
EmptyPctLbl.Caption := FormatFloat('0.00',100.0*EmptyTime/TotalTime);
SplitPctLbl.Caption := FormatFloat('0.00',100.0*SplitTime/TotalTime);
WorkPctLbl.Caption := FormatFloat('0.00',100.0*WorkTime/TotalTime);
OverheadPctLbl.Caption := FormatFloat('0.00',100.0*Overhead/TotalTime);
RemainderPctLbl.Caption := FormatFloat('0.00',100.0*Remainder/TotalTime);
StopOverheadLbl.Caption := FormatFloat('0.0000000',TProfilingStopWatch.GetOverheadForStop);
SplitOverheadLbl.Caption := FormatFloat('0.0000000',TProfilingStopWatch.GetOverheadForSplit);
end;
procedure TMainFrm.SetOverheadBtn_Click(Sender: TObject);
begin
TProfilingStopWatch.SetOverheadForStop(StrToFloat(StopOverheadEbx.Text));
TProfilingStopWatch.SetOverheadForSplit(StrToFloat(SplitOverheadEbx.Text));
StopOverheadLbl.Caption := FormatFloat('0.0000000',TProfilingStopWatch.GetOverheadForStop);
SplitOverheadLbl.Caption := FormatFloat('0.0000000',TProfilingStopWatch.GetOverheadForSplit);
end;
procedure TMainFrm.RecalibrateBtn_Click(Sender: TObject);
begin
TProfilingStopWatch.CalibrateOverhead;
StopOverheadLbl.Caption := FormatFloat('0.0000000',TProfilingStopWatch.GetOverheadForStop);
SplitOverheadLbl.Caption := FormatFloat('0.0000000',TProfilingStopWatch.GetOverheadForSplit);
end;
end.